package nku.csc360;

//Raj Akula
//CSC 360
//Homework 7
//Draws Sine Graph

//Import Functions
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Polygon;

//Class that implements the sine wave JFrame and builds it and draws it using a panel
@SuppressWarnings("serial")
class SineWave extends JFrame {
  //Once an instance of SineWave Frame is Created calls panel to draw required lines and sine wave
  public SineWave() {
    add(new NewPanel());
  }

  public static void main(String[] args) {
  	//Setting up Frame
    SineWave frame = new SineWave();
    frame.setTitle("TestPanelDrawing");
    frame.setSize(500, 500);
    frame.setLocationRelativeTo(null); // Center the frame
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }
}

@SuppressWarnings("serial")
class NewPanel extends JPanel {
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    //Drawing all the components
    //*Just as a note the panel is of fixed size if you change shape of your window it does not 
    //*resize your graph
    g.drawLine(50, 250, 450, 250);
    g.drawLine(250, 50, 250, 450);
    g.drawLine(250, 50, 260, 60);
    g.drawLine(450, 250, 440, 240);
    g.drawLine(250, 50, 240, 60 );
    g.drawLine(450, 250, 440, 260);
    g.drawString("-2\u03c0", 150, 270);
    g.drawString("+2\u03c0", 350, 270);
    g.drawString("Sine Wave", 220, 40);
    g.drawString("Y", 260, 60);
    g.drawString("X", 440, 240);
    g.drawString("0", 255, 265);

	Polygon polygon = new Polygon();
	for (int x = -100; x <= 100; x++) {
		polygon.addPoint(x + 250, 250 - (int)(50 * Math.sin((x / 100.0) * 2 * Math.PI)));
	}
	 g.drawPolygon(polygon);
  }
}
